<?php
namespace Library;
use Phalcon\Logger\Adapter\File as Logger;
use Phalcon\Db\Profiler;
class myLient {
    protected $log;
    protected $_profile;
    public function __construct(){
        $this->log=new Logger('../data/log.log');
        $this->_profile=new Profiler();
    }
    
    public function  beforeQuery($event,$connect){
        $this->_profile->startProfile($connect->getSQLStatement());
    }
    
    public  function afterQuery($event,$connect){
        $this->_profile->stopProfile($connect);
        $this->getProfiler();
    }
    public function getProfiler()
    {
        $d=$this->_profile;
        $arr="当前执行的SQL情况如下\r\n";
        $arr.='执行的SQL语句是：'.$d->getLastProfile()->getSqlStatement()."\r\n";
        $arr.='执行的SQL开始时间：'.$d->getLastProfile()->getInitialTime()."\r\n";
        $arr.='执行的SQL结束时间：'.$d->getLastProfile()->getFinalTime()."\r\n";
        $arr.='执行的SQL总耗时：'.$d->getLastProfile()->getTotalElapsedSeconds()."\r\n";
        $this->log->log($arr,\Phalcon\Logger::INFO);
        
    }
}
